import React, { Component } from 'react';
import {connect} from 'react-redux'
import { Table, Tooltip, Tag, Popconfirm, message, Button, Select } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';

// 引入自定义组件


// 引入自定义操作
import { ChangeAdminBaseInfoActivate, AdminGetDataSaga, AdminChangeTaskAuditSaga } from '../../../../redux/actions/admin';
// 选择器
const { Option } = Select

class TaskForm extends Component {

  // 用于记录每一行的信息
    constructor(props){
      super(props)
      this.state = {
        // 用来传递点击当行的数据
        data: {}
      }
    }

    componentDidMount(){
      const obj = this.props.AdminLoginState
      this.props.AdminGetDataSaga(obj)
    }

    // 雇主用户任务title点击触发的函数
    onConfirmTitle = () => {
     console.log("taskForm is 点击title")
    }

    // 修改任务审核状态
    handleChangeAudit = (record) => {
        // console.log(4444, record)
        this.props.AdminChangeTaskAuditSaga({id: record.key, audit: record.audit})
    }


    render() {
      const columns = [
        {
          title: '任务标题',
          dataIndex: 'tasktitle',
          key: 'tasktitle',
          width: 150,
        },
        {
          title: '任务赏金',
          dataIndex: 'bounty',
          key: 'bounty',
          width: 100,
        },
        {
            title: "任务发布时间",
            dataIndex: "startdate",
            key: "startdate"
        },
        {
          title: '任务截止时间',
          dataIndex: 'enddate',
          key: 'enddate',
        },
        {
            title: '任务审核状态',
            dataIndex: 'audit',
            key: 'audit',
            render: (tag, record, index) => (
                <Select 
                    className='adminSelect'
                    defaultValue={tag} 
                    disabled={tag == "1" ? true : false}
                    onChange={(value)=> {
                      record.audit = value
                      const obj = record
                      this.handleChangeAudit(record)
                    }}
                >
                        <Option value="0">待审核</Option>
                        <Option value="1">已通过</Option>
                        <Option value="2">未通过</Option>
                </Select>
            ),
        },
        {
          title: '任务类型',
          dataIndex: 'type_name',
          key: 'type_name',
        },
        {
            title: '发布者',
            key: 'nickname',
            dataIndex: 'nickname',
        },
        {
          title: '联系方式',
          key: 'email',
          dataIndex: 'email',
        },
        {
          title: '任务描述',
          key: 'taskintro',
          dataIndex: 'taskintro',
          ellipsis: {
              showTitle: false,
          },
          render: taskintro => (
              <Tooltip placement='topLeft' title={taskintro}>
                  {taskintro}
              </Tooltip>
          )
        },
      ];
      const { form_data } = this.props.BaseAdminInfo
      console.log(1111, form_data)
      
      console.log("handleChangeAudit is on click", this.props.BaseAdminInfo)
      return (
        <>
          <Table columns={columns} dataSource={form_data}  scroll={{ y: 600 }}  />
        </> 
      )
    }
}

export default connect(
    state => ({
      baseUserInfoState: state.PublicReducer.baseUserInfo,
      TaskWMPState: state.TaskWorkerManagePageReducer.tasks,
      TaskMMPState: state.TaskMasterManagePageReducer.tasks,


      BaseAdminInfo: state.AdminReducer.baseAdminInfo,
      AdminLoginState: state.PublicReducer.adminLoginState
    }),
    {
        ChangeAdminBaseInfoActivate, 
        AdminGetDataSaga,
        AdminChangeTaskAuditSaga
    }
)(TaskForm)